<?php
// 连接数据库

$host = 'localhost:3306';
$user = 'root';
$pwd = 'root';
$dbname = 'kaola';

$con = mysqli_connect($host, $user, $pwd, $dbname);

// 测试数据库是否链接成功
if (!$con) {

  die('数据库连接失败');   //die这个方法结束整个php语句
}


// 数据返回给前端
$result = [];


// 前端携带参数  cart_id
$id = $_POST['id'];

if ($id) {
  $sql = "DELETE FROM cart WHERE cart_id = $id";
  $run = mysqli_query($con, $sql);
  if ($run > 0) {
    $result['status'] = true;
    $result['msg'] = '删除成功';
  } else {
    $result['status'] = false;
    $result['msg'] = '数据库错误';
  }
} else {
  $result['status'] = false;
  $result['msg'] = '前端数据有误';
}

echo (json_encode($result));
